1 package edu.jiangxin.apktoobox.swing.treetable;
2
3 import edu.jiangxin.apktoolbox.swing.treetable.MyAbstractTreeTableModel;
4 import edu.jiangxin.apktoolbox.swing.treetable.MyTreeTable;
5
6 import java.awt.Container;
7 import java.awt.GridLayout;
8 import java.util.ArrayList;
9 import java.util.Date;
10 import java.util.List;
11
12 import javax.swing.JFrame;
13 import javax.swing.JScrollPane;
14 import javax.swing.SwingUtilities;
15 import javax.swing.UIManager;
16
17
18 public class TreeTableMain extends JFrame {
19
20
21 public TreeTableMain() {
22 super("Tree Table Demo");
23
24 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
25
26 setLayout(new GridLayout(0, 1));
27
28 MyAbstractTreeTableModel treeTableModel = new MyDataModel(createDataStructure());
29
30 MyTreeTable myTreeTable = new MyTreeTable(treeTableModel);
31
32 Container cPane = getContentPane();
33
34 cPane.add(new JScrollPane(myTreeTable));
35
36 setSize(1000, 800);
37 setLocationRelativeTo(null);
38
39
40 }
41
42
43 private static MyDataNode createDataStructure() {
44 List<MyDataNode> children1 = new ArrayList<MyDataNode>();
45 children1.add(new MyDataNode("N12", "C12", new Date(), Integer.valueOf(50), null));
46 children1.add(new MyDataNode("N13", "C13", new Date(), Integer.valueOf(60), null));
47 children1.add(new MyDataNode("N14", "C14", new Date(), Integer.valueOf(70), null));
48 children1.add(new MyDataNode("N15", "C15", new Date(), Integer.valueOf(80), null));
49
50 List<MyDataNode> children2 = new ArrayList<MyDataNode>();
51 children2.add(new MyDataNode("N12", "C12", new Date(), Integer.valueOf(10), null));
52 children2.add(new MyDataNode("N13", "C13", new Date(), Integer.valueOf(20), children1));
53 children2.add(new MyDataNode("N14", "C14", new Date(), Integer.valueOf(30), null));
54 children2.add(new MyDataNode("N15", "C15", new Date(), Integer.valueOf(40), null));
55
56 List<MyDataNode> rootNodes = new ArrayList<MyDataNode>();
57 rootNodes.add(new MyDataNode("N1", "C1", new Date(), Integer.valueOf(10), children2));
58 rootNodes.add(new MyDataNode("N2", "C2", new Date(), Integer.valueOf(10), children1));
59 rootNodes.add(new MyDataNode("N3", "C3", new Date(), Integer.valueOf(10), children2));
60 rootNodes.add(new MyDataNode("N4", "C4", new Date(), Integer.valueOf(10), children1));
61 rootNodes.add(new MyDataNode("N5", "C5", new Date(), Integer.valueOf(10), children1));
62 rootNodes.add(new MyDataNode("N6", "C6", new Date(), Integer.valueOf(10), children1));
63 rootNodes.add(new MyDataNode("N7", "C7", new Date(), Integer.valueOf(10), children1));
64 rootNodes.add(new MyDataNode("N8", "C8", new Date(), Integer.valueOf(10), children1));
65 rootNodes.add(new MyDataNode("N9", "C9", new Date(), Integer.valueOf(10), children1));
66 rootNodes.add(new MyDataNode("N10", "C10", new Date(), Integer.valueOf(10), children1));
67 rootNodes.add(new MyDataNode("N11", "C11", new Date(), Integer.valueOf(10), children1));
68 rootNodes.add(new MyDataNode("N12", "C7", new Date(), Integer.valueOf(10), children1));
69 rootNodes.add(new MyDataNode("N13", "C8", new Date(), Integer.valueOf(10), children1));
70 rootNodes.add(new MyDataNode("N14", "C9", new Date(), Integer.valueOf(10), children1));
71 rootNodes.add(new MyDataNode("N15", "C10", new Date(), Integer.valueOf(10), children1));
72 rootNodes.add(new MyDataNode("N16", "C11", new Date(), Integer.valueOf(10), children1));
73 MyDataNode root = new MyDataNode("R1", "R1", new Date(), Integer.valueOf(10), rootNodes);
74
75 return root;
76 }
77
78 public static void main(final String[] args) {
79 Runnable gui = new Runnable() {
80
81 public void run() {
82 try {
83 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
84 } catch (Exception e) {
85 e.printStackTrace();
86 }
87 new TreeTableMain().setVisible(true);
88 }
89 };
90 SwingUtilities.invokeLater(gui);
91 }
92 }